package com.lx.controller;

import com.lx.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
@RequestMapping("param")
public class ParamController {

    // 获取前端传递的单个参数
    @RequestMapping("/oneParam")
    public String param(@RequestParam("username") String name, Model model) {
        model.addAttribute("msg", "您输入的name：" + name);
        return "param";
    }

    // 获取多个参数可以封装一个实体类接受参数
    @RequestMapping("user")
    public String entity(User user, Model model) {
        model.addAttribute("msg", user);
        return "param";
    }

    // 使用ModelMap讲数据回显给前端
    @RequestMapping("modelMap")
    public String modelMap(ModelMap modelMap) {
        modelMap.addAttribute("msg", "modelMap");
        return "param";
    }
}
